package org.quarenden.demo.aggregate;

import org.quarenden.demo.feign.IdGeneratorFeignClient;
import org.quarenden.demo.feign.MicroService1FeignClient;
import org.quarenden.demo.feign.MicroService2FeignClient;
import org.quarenden.demo.pojo.MicroService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import rx.Observable;

@Service
public class AggregationService {
    @Autowired
    private IdGeneratorFeignClient idGeneratorFeignClient;

    @Autowired
    private MicroService1FeignClient microService1FeignClient;

    @Autowired
    private MicroService2FeignClient microService2FeignClient;

    public Observable<String> getId(String idType){
        return Observable.create(observer -> {
            String id = idGeneratorFeignClient.idGeneratorPost(idType);
            observer.onNext(id);
            observer.onCompleted();
        });
    }

    public Observable<MicroService> getMicroService1(String id){
        return Observable.create(observer -> {
           MicroService microService = microService1FeignClient.getMicroService(id);
           observer.onNext(microService);
           observer.onCompleted();
        });
    }

    public Observable<MicroService> getMicroService2(String id){
        return Observable.create(observer -> {
            MicroService microService = microService2FeignClient.getMicroService(id);
            observer.onNext(microService);
            observer.onCompleted();
        });
    }
}
